﻿using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ImageProcessor.Shared;
using ImageProcessor.Shared.ImageExtensions;
using System.Drawing;
using ImageProcessor.Shared.ImageExtensions;
using Fourier;

namespace ImageProcessor.Mish
{
    public class IFTu : ImageProcessorBaseVM
    {
        private ImageSource _resultImage;
        private ImageSource _resultImage2;
        private double _chance;
        private static Random _random = new Random();

        public IFTu(MainViewModel mainVM)
            : base(mainVM)
        {
            Chance = 10;
        }

        public ImageSource ResultImage
        {
            get { return _resultImage; }
            private set
            {
                if(_resultImage == value)
                    return;
                _resultImage = value;
                OnPropertyChanged("ResultImage");
            }
        }
        
        public double Chance
        {
            get { return _chance; }
            set
            {
                if(_chance == value)
                    return;
                _chance = value;
                OnPropertyChanged("Chance");
            }
        }

        protected override void Execute(object obj)
        {
            var bitmap = ((BitmapSource)MainVM.SourceImage).BitmapSourceToBitmap();

            var fft = new ImageCalc(bitmap);
            var res = fft.IFT();

            ResultImage = res.Obj.BitmapToBitmapSource();            
        }

        protected override bool CanExecute(object obj)
        {
            return MainVM.SourceImage != null;
        }

                        
    }    
}